<template>
	<!-- 财务对账 -->
	<view class="page-body">
		<!-- 页面内容开始 -->

		<!-- 表格搜索组件开始 -->
		<vk-data-table-query v-model="queryForm1.formData" :columns="queryForm1.columns" @search="search"
			:clearable="false">
		</vk-data-table-query>
		<!-- 表格搜索组件结束 -->

		<view style="margin: 40rpx 0">
			<!-- 			<el-radio-group v-model="radio1" size="medium" @change="timechange">
				<el-radio-button label="本月"></el-radio-button>
				<el-radio-button label="上个月"></el-radio-button>
			</el-radio-group> -->

			<!-- 			<text style="color: gray;margin:0 40rpx;">充值金额：{{money.all}}</text>
			<text style="color: gray;margin:0 40rpx;">代理佣金比例：{{money.yjbl}}%</text>
			<text style="color: gray;margin:0 40rpx;">预计佣金：{{money.yjyj}}</text> -->

			<!-- <text style="color: gray;margin:0 40rpx;"> </text> -->

			<el-button type="success" size="small" @click="exportData()">导出筛选结果
			</el-button>
			<text style="color: gray;margin:0 40rpx;">充值金额：{{money.all}}</text>
		</view>

		<!-- 表格组件开始 -->
		<vk-data-table ref="table1" :action="table1.action" :columns="table1.columns" :query-form-param="queryForm1"
			:right-btns="['detail_auto']" :row-no="true" :pagination="true">
		</vk-data-table>
		<!-- 表格组件结束 -->

		<!-- 页面内容结束 -->
	</view>
</template>

<script>
	var that; // 当前页面对象
	var vk = uni.vk; // vk实例
	var originalForms = {}; // 表单初始化数据

	export default {
		data() {
			// 页面数据变量
			return {
				radio1: "本月",
				money: {
					all: "0",
					yjyj: 0,
					yjbl: 0
				},
				// 页面是否请求中或加载中
				loading: false,
				// init请求返回的数据
				data: {

				},
				// 表格相关开始 -----------------------------------------------------------
				table1: {
					// 表格数据请求地址
					action: "admin/pages/kh/yhsj/czjl/copyright_getList",
					// 表格字段显示规则
					columns: [{
							key: "",
							title: "用户信息",
							type: "group",
							minWidth: 240,
							align: "left",
							columns: [{
									key: "user_id",
									title: "用户ID",
									type: "text"
								},
								{
									key: "nickname",
									title: "用户昵称",
									type: "text",
									"defaultValue": "未设置"
								},
								{
									key: "user_register_date",
									title: "注册时间",
									type: "time"
								},
								{
									key: "os_name",
									title: "用户系统类型",
									type: "text"
								},
							],
						},

						{
							"key": "pay_status",
							"title": "支付状态",
							"type": "tag",
							"width": 80,
							data: [{
									value: 0,
									label: "未支付",
									tagType: "danger"
								},
								{
									value: 1,
									label: "已支付",
									tagType: "success"
								},
								{
									value: 2,
									label: "已退款",
									tagType: "warning"
								}
							]
						},

						{
							key: "",
							title: "充值信息",
							type: "group",
							minWidth: 250,
							align: "left",
							columns: [{
									"key": "platform",
									"title": "平台",
									"type": "tag",
									"sortable": "custom",
									data: [{
											value: "wxpay",
											label: "微信支付",
											tagType: "success"
										},
										{
											value: "tt",
											label: "抖音支付",
											tagType: "warning"
										},
										{
											value: "ks",
											label: "快手支付",
											tagType: "error"
										},
										{
											value: "wxh5",
											label: "公众号H5",
											tagType: "success"
										},
										{
											value: "h5",
											label: "H5",
											tagType: "warning"
										},
										{
											value: "quickapp",
											label: "快应用",
											tagType: "error"
										},
										{
											value: "PayPal",
											label: "PayPal",
											tagType: "success"
										},
									]
								},
								{
									key: "recharge_amount",
									title: "充值金额",
									type: "money"
								},
								{
									key: "shifu_amount",
									title: "实付金额",
									type: "money",
									defaultValue: 0
								},
								{
									key: "out_trade_no",
									title: "支付单号",
									type: "text"
								},
							],
						},

						{
							key: "",
							title: "小程序信息",
							type: "group",
							minWidth: 180,
							align: "left",
							columns: [{
									key: "appid",
									title: "appid",
									type: "text"
								},
								{
									key: "appname",
									title: "小程序名称",
									type: "text"
								},
							],
						},

						{
							key: "",
							title: "推广信息",
							type: "group",
							minWidth: 240,
							align: "left",
							columns: [{
									key: "tg_pt",
									title: "推广平台",
									type: "text"
								},
								// { key: "changed_num", title: "剩余金蝉", type: "text" },
								{
									key: "middleman_id",
									title: "隶属机构",
									type: "text"
								},
								{
									key: "invite_code",
									title: "上级邀请码",
									type: "text"
								},
								{
									key: "tv_name",
									title: "充值来源",
									type: "text"
								},
							],
						},
						{
							key: "",
							title: "其他信息",
							type: "group",
							minWidth: 240,
							align: "left",
							columns: [{
									key: "province",
									title: "用户省份",
									type: "text"
								},
								{
									key: "city",
									title: "用户城市",
									type: "text"
								},
								{
									key: "_add_time",
									title: "添加时间",
									type: "time"
								},
								{
									key: "remark",
									title: "备注",
									type: "text"
								},
							],
						},

					],
					// 多选框选中的值
					multipleSelection: [],
					// 当前高亮的记录
					selectItem: ""
				},
				// 表格相关结束 -----------------------------------------------------------
				// 表单相关开始 -----------------------------------------------------------
				// 查询表单请求数据
				queryForm1: {
					// 查询表单数据源，可在此设置默认值
					formData: {
						_add_time: []
					},
					// 查询表单的字段规则 fieldName:指定数据库字段名,不填默认等于key
					columns: [{
							"key": "querykey",
							"title": "查询密钥",
							"type": "text",
							"width": 200,
							"mode": "="
						},
						{
							"key": "tv_name",
							"title": "剧名",
							"type": "text",
							"width": 200,
							"mode": "="
						},
						{
							key: "_add_time",
							title: "时间",
							type: "datetimerange",
							width: 400,
							mode: "[]"
						}
					]
				},
				form1: {
					// 表单请求数据，此处可以设置默认值
					data: {

					},
					// 表单属性
					props: {
						// 表单请求地址
						action: "",
						// 表单字段显示规则
						columns: [],
						// 表单验证规则
						rules: {

						},
						// add 代表添加 update 代表修改
						formType: "",
						// 是否显示表单的弹窗
						show: false
					}
				},
				// 其他弹窗表单
				formDatas: {},
				// 表单相关结束 -----------------------------------------------------------
			};
		},
		// 监听 - 页面每次【加载时】执行(如：前进)
		onLoad(options = {}) {
			that = this;
			vk = that.vk;
			that.options = options;
			that.init(options);
		},
		// 监听 - 页面【首次渲染完成时】执行。注意如果渲染速度快，会在页面进入动画完成前触发
		onReady() {},
		// 监听 - 页面每次【显示时】执行(如：前进和返回) (页面每次出现在屏幕上都触发，包括从下级页面点返回露出当前页面)
		onShow() {
			// if (vk.vuex.get('$user.userInfo.role[0]') != "admin") {
			// 	vk.navigateToLogin();
			// }
		},
		// 监听 - 页面每次【隐藏时】执行(如：返回)
		onHide() {},
		// 函数
		methods: {
			// 页面数据初始化函数
			init(options) {
				originalForms["form1"] = vk.pubfn.copyObject(that.form1);
				vk.vuex.set('$app.time', vk.pubfn.getCommonTime(new Date()))
				//页面载入时默认加载本月数据
				setTimeout(() => {
					let monthStart = vk.vuex.get('$app.time.monthStart');
					let monthEnd = vk.vuex.get('$app.time.monthEnd');
					this.tongji(monthStart, monthEnd)
				}, 500)
			},
			// 页面跳转
			pageTo(path) {
				vk.navigateTo(path);
			},
			// 表单重置
			resetForm() {
				vk.pubfn.resetForm(originalForms, that);
			},
			// 搜索
			search() {

				that.$refs.table1.search();
				if (this.queryForm1.formData._add_time) {
					let recharge_source = this.queryForm1.formData.tv_name
					let search_starttime = this.queryForm1.formData._add_time[0]
					let search_endtime = this.queryForm1.formData._add_time[1]
					let recharge_querykey = this.queryForm1.formData.querykey
					this.tongji3(recharge_source, search_starttime, search_endtime, recharge_querykey)
				}

			},
			// 刷新
			refresh() {
				that.$refs.table1.refresh();
			},
			// 获取当前选中的行的数据
			getCurrentRow() {
				return that.$refs.table1.getCurrentRow();
			},
			async timechange(e) {
				if (e == "本月") {
					let monthStart = vk.vuex.get('$app.time.monthStart');
					let monthEnd = vk.vuex.get('$app.time.monthEnd');
					//同步获取一下充值订单列表
					this.queryForm1.formData._add_time = [] //必须先清空，否则数据会出错
					this.queryForm1.formData._add_time.push(monthStart);
					this.queryForm1.formData._add_time.push(monthEnd);
					this.search()
				}
				if (e == "上个月") {
					let lastMonthStart = vk.vuex.get('$app.time.lastMonthStart');
					let lastMonthEnd = vk.vuex.get('$app.time.lastMonthEnd');
					//同步获取一下充值订单列表
					this.queryForm1.formData._add_time = [] //必须先清空，否则数据会出错
					this.queryForm1.formData._add_time.push(lastMonthStart);
					this.queryForm1.formData._add_time.push(lastMonthEnd);
					this.search()
				}
			},
			async tongji3(recharge_source, StartTime, EndTime, querykey) {
				vk.callFunction({
					url: 'admin/pages/kh/yhsj/czjl/tongji3',
					title: '请求中...',
					data: {
						recharge_source: recharge_source,
						StartTime: StartTime,
						EndTime: EndTime,
						querykey
					},
					success: (data) => {
						console.log("data=", data);
						//保留*位小数
						this.money.all = vk.pubfn.toDecimal(data.jrczje / 100, 3);
					}
				});
			},
			exportData() {
				that.$refs.table1.exportExcel({
					fileName: "导出数据",
					title: "正在导出数据...",
					pageIndex: 1,
					pageSize: -1, // 此值为-1，代表导出所有数据
				});
			},
			// uni.showToast的简易封装
			toast(title, icon = "none", mask = false) {
				uni.showToast({
					title,
					icon,
					mask,
					duration: 1500
				});
			},
			// uni.showModal的简易封装
			alert(content, title = "提示") {
				uni.showModal({
					title,
					content,
					showCancel: false
				});
			}
		},
		// 监听属性
		watch: {

		},
		// 过滤器
		filters: {

		},
		// 计算属性
		computed: {

		}
	};
</script>
<style lang="scss" scoped>
	.page-body {}
</style>